package com.purchase.jd.http;


import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ByteUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.purchase.util.FileUtils;
import com.purchase.util.HttpUtils;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;

/**
 * Http请求方法
 * @author saw
 * @date 2021/11/8
 */
public class JdHttpUtil {

    /**
     * 获取二维码并扫码登录
     * @param headers   表头
     * @param url   请求地址
     * @return
     */
    public static HttpResponse scanCode(Map<String,String> headers, String url){
        //获取返回response
         HttpResponse response = HttpUtils.get(headers, url);
        //获取图片流
        byte[] imgByte = response.bodyBytes();
        //转成流
        FileUtils.fileWrite("QCode.png", imgByte);
        return response;
    }

}
